﻿@{
    ViewBag.Title = "Register";
    Layout = "~/Views/Shared/Main.cshtml";
}
@using Forum.Web.BaseCode

@section head
{
  @Html.Raw(ForumStyle.Register)
  @Html.Raw(ForumScript.Forum)
<script type="text/javascript">
    function checkusername()
    {
        return baseValidate("LoginName", "用户名");
    }

    function checkemail()
    {
        var flag = baseValidate("Email", "电子邮件");
        if (flag)
        {
            var reg = /^\w+([-+.]\w+)*@@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            flag = reg.test($("#Email").val());

            setMessage("电子邮件格式不正确", flag);
        }
        return flag;
    }

//    function checkmobile()
//    {
//        var flag = baseValidate("Mobile", "手机");
//        if (flag)
//        {
//            var reg = /^\d{11}$/;
//            flag = reg.test($("#Mobile").val());

//            setMessage("手机格式不正确，应为11位数字", flag);
//        }
//        return flag;
//    }

    function baseValidate(field, message)
    {
        var flag = false;
        var value = $.trim($("#" + field).val());
        if (value == "")
        {
            setMessage("请输入" + message, false);
            flag = false;
        }
        else
        {
            setMessage("", true);

            var url = '@(ForumPath.VirtualRoot + "Member/Exist/")';
            $.ajaxSetup({ async: false }); //设为同步
            $.get(url, { field: field, value: value }, function (data)
            {
                setMessage(message + "已经存在", (data != "true"));

                flag = (data != "true");
                
            });
        }
        return flag;
    }

    function checkpwd()
    {
        var pwd = $.trim($("#Password").val());

        var isCorrect = (pwd != "");
        setMessage("请输入密码", isCorrect);
        return isCorrect
    }

    function checkpwd2()
    {
        var pwd = $.trim($("#Password").val());
        var isCorrect = (pwd == $.trim($("#Password2").val()));
        setMessage("两次输入的密码不同", isCorrect);
        return isCorrect
        
    }

    function setMessage(message, isCorrect)
    {
        if (isCorrect)
        {
            $("#errormessage").removeClass("onerror");
            $("#errormessage").html("");
        }
        else
        {
            $("#errormessage").addClass("onerror");
            $("#errormessage").html(message);
        }
    }

    function checksec()
    {
        var flag = false;
        var url = '@ForumPath.CheckCode';
        var value = $("#ValidateCode").val();
        $.ajaxSetup({ async: false }); //设为同步
        $.get(url, { key: '', value: value }, function (data)
        {
            setMessage("验证码错误", (data == "true"));
            flag = (data == "true");
        });
        return flag;
    }

    function form_submit()
    {
      
        var flag = checkusername();
        if (!flag)
        {
            return false;
        }        

        flag = checkpwd();
        if (!flag)
        {
            return false;
        }

        flag = checkpwd2();
        if (!flag)
        {
            return false;
        }

        flag = checkemail();
        if (!flag)
        {
            return false;
        }
          

//        flag = checkmobile();
//        if (!flag)
//        {
//            return false;
//        }        
        
        flag = checksec();

          
        return flag;
    }

    $(function ()
    {
        @Html.Raw((string)this.ViewData["initjs"])
        $("#frmMain").bind("submit", function ()
        {
            return form_submit();
        });

        $("#btnSubmit").bind("click",function()
        {
           
            try
            {               
                $("#frmMain").submit();                
            }
            catch(e)
            {
                alert("error");

            }
        });
   
    });
    </script>
}
 <div class="main">
       <div id="errormessage" style="height:40px;margin-top: 20px;"></div>
       <form method="post" id="frmMain" action="@(ForumPath.VirtualRoot + "member/add")">
        <div class="loginbar">
            <div class="loginbar_left">
                
                <table cellpadding="0" cellspacing="0" border="0" width="100%">                    
                    <tr>
                        <td class="tit">
                            用户名:
                        </td>
                        <td class="con" colspan="2">
                            <input type="text" id="LoginName" name="LoginName" onblur="checkusername()" autocomplete="off" />
                        </td>
                        <td>
                            *
                        </td>
                    </tr>
                    <tr>
                        <td class="tit">
                            密码:
                        </td>
                        <td class="con" colspan="2">
                            <input type="password" name="Password" id="Password" onblur="checkpwd()" />
                        </td>
                        <td>
                            *
                        </td>
                    </tr>
                    <tr>
                        <td class="tit">
                            确认密码:
                        </td>
                        <td class="con" colspan="2">
                            <input type="password" name="Password2" size="25" id="Password2" onblur="checkpwd2()" />
                        </td>
                        <td>
                            *
                        </td>
                    </tr>
                    <tr>
                        <td class="tit">
                            Email:
                        </td>
                        <td class="con" colspan="2">
                            <input type="text" name="Email" autocomplete="off" id="Email" onblur="checkemail()" />
                        </td>
                        <td>
                            *
                        </td>
                    </tr>
                    <tr>
                        <td class="tit">
                            验证码:
                        </td>
                        <td class="content">
                            <input type="text" onblur="checksec()" name="ValidateCode" id="ValidateCode" 
                                autocomplete="off" />
                        </td>
                        <td class="text">
                            <img id="imgValidatecode" onmouseup="RefreshImage()" alt="点击重刷新" align="absmiddle"
                                style="cursor: pointer" class="validate_code" src="@(ForumPath.ValidateCode + "?&c=1")" />
                        </td>
                        <td>
                            *
                        </td>
                    </tr>
                </table>
            </div>
            <div class="loginbar_right">
                <p>
                    已有帐号？<a href="javascript:;">现在登录</a>
                </p>
            </div>
            <div class="clear">
            </div>
        </div>
        </form>
        <div class="button">
            <input id="btnSubmit" type="button" value="提交" /></div>
        <div class="footer">
            <div class="left">
                <p>
                    Powered by<a href="javascript:;" class="bold"> Discuz!</a> X1.5 Licensed</p>
                <p>
                    © 2001-2010 <a href="javascript:;">Comsenz Inc.</a></p>
            </div>
            <div class="right">
                <p>
                    <a href="javascript:;">Archiver</a>|<a href="javascript:;" class="bold">银光中国</a> ( 沪ICP备10206900号
                    )</p>
                <p>
                    GMT+8, 2011-5-29 19:01 , Processed in 0.072292 second(s), 6 queries .</p>
            </div>
        </div>
    </div>
